a=[]
for i in range(100,1000):
    for y in range(2,i):
        if i%y==0:
            break
    else:
        a.append(i)
n=0
k=0
f1=0
s0="zero"
s1="one"
s2="two"
s3="three"
s4="four"
s5="five"
s6="six"
s7="seven"
s8="eight"
s9="nine"
s10=input().split()
str="";
for i in range(len(s10)):
    if s10[i]==s0:
        str=str+"0"
    if s10[i]==s1:
        str=str+"1"
    if s10[i]==s2: 
        str=str+"2"
    if s10[i]==s3:
        str=str+"3"
    if s10[i]==s4:
        str=str+"4"
    if s10[i]==s5:
        str=str+"5"
    if s10[i]==s6:
        str=str+"6"
    if s10[i]==s7:
        str=str+"7"
    if s10[i]==s8:
        str=str+"8"
    if s10[i]==s9:
        str=str+"9"
if str!="":
    n=int(str)
if n==0 or n<=99 or n>=1000:
    print("Wrong input")
else:
    if n > 997:
        print("997")
    else:
        if n in a:
            print(n)
        else:
            for i in range(len(a)):
                if a[i]>n:
                    f=i
                if a[i]<n:
                    f1=i
            if abs(a[f1]-n)>abs(a[f1+1]-n):
                print(a[f1+1])
            else:
                print(a[f1])
